<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('数仓自助查询参数')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="row" style="margin-left:2px">
        <div class="col-sm-10">
            <form class="form-horizontal m" id="form-group-add">
                <input type="hidden" th:value="${type}" id="type">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">时间范围：</label>
                    <div class="col-sm-9">
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" id="dateBegin" autocomplete="off" placeholder="yyyy-MM-dd"/>
                            <span class="input-group-addon">到</span>
                            <input type="text" class="input-sm form-control" id="dateEnd" autocomplete="off" placeholder="yyyy-MM-dd"/>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">排序条件：</label>
                    <div class="col-sm-9">
                        <input type="text" id="orderBy" class="form-control" autocomplete="off" value="ID_DIM_DAY_OCCUR DESC"/>
                    </div>
                </div>
            </form>
            <h4 class="form-header h4">汇总设置 <a href="#" onclick="hideOrShow()" style="cursor: pointer;" ><i class="glyphicon glyphicon-chevron-down"></i></a></h4>
            <form id="form2" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-3 control-label">时间维：</label>
                    <div class="col-sm-9">
                        <label class="check-box">
                            <input type="radio" value="D" name="dateType">日</label>
                        <label class="check-box">
                            <input type="radio" value="M" name="dateType">月</label>
                        <label class="check-box">
                            <input type="radio" value="Q" name="dateType">季</label>
                        <label class="check-box">
                            <input type="radio" value="Y" name="dateType">年</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">同环比：</label>
                    <div class="col-sm-9">
                        <label class="check-box">
                            <input id="tb" type="checkbox" value="tb" text="">同比
                        </label>
                        <label class="check-box">
                            <input id="hb" type="checkbox" value="hb" text="">环比
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">度量排序：</label>
                    <div class="col-sm-9">
                        <label class="check-box">
                            <input name="order" type="radio" value="desc" text="" checked>降序
                        </label>
                        <label class="check-box">
                            <input name="order" type="radio" value="asc" text="">升序
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">汇总字段：</label>
                    <div class="col-sm-9" id="groupByFldsDiv">
                        <label class="check-box" th:each="tbFld:${tbFlds}" th:if="${tbFld.idPubfld.startsWith('ID_DIM_')}" th:unless="${tbFld.idPubfld.startsWith('ID_DIM_DAY')}">
                            <input type="checkbox" th:value="${tbFld.idPubfld}" th:text="${tbFld.naPubfld}" />
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">汇总结果：</label>
                    <div class="col-sm-9" id="sumValueFldsDiv">
<!--                        <input type="text" id="sumvaluedes" class="form-control" placeholder="默认count(*)">-->
                        <label class="check-box">
                            <input type="checkbox" value="count(*)">总条数
                        </label>
                        <label class="check-box" th:each="tbFld:${tbFlds}" th:if="${tbFld.idPubfld.startsWith('VALUE_')}">
                            <input type="checkbox" th:value="${tbFld.idPubfld}" th:text="${tbFld.naPubfld}" />
                        </label>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: datetimepicker-js" />
<script>
    var searchDataParam = function () {
        var startDay = $("#dateBegin").val();
        var endDay = $("#dateEnd").val();
        if(startDay=="" || endDay=="") {
            $.modal.alertError("日期不完整");
            return null;
        }
        var param={"startDay":$("#dateBegin").val(),"endDay":$("#dateEnd").val(),"orderBy":$("#orderBy").val()};
        var type = $("#type").val();
        if(type=="statistics") { //汇总
            param.dateType=$('input:radio[name=dateType]:checked').val();
            var groupFldChecks = $("#groupByFldsDiv").find("input[type='checkbox']:checked");
            var sumFldChecks = $("#sumValueFldsDiv").find("input[type='checkbox']:checked");
            var groupFlds=[];
            $.each(groupFldChecks,function (index,item) {
                groupFlds.push($(this).val());
            });
            var sumFlds=[];
            $.each(sumFldChecks,function (index,item) {
                sumFlds.push($(this).val());
            });
            param.groupFlds = groupFlds;
            param.sumFlds = sumFlds;
            param.fgDetail=false;
            //param.sumValueDes = $("#sumValueDes").val();
        } else {
            param.fgDetail=true;
        }
        return param;
    }
    function submitHandler() {
        return searchDataParam();
    }
$(function (){
    $("#dateBegin").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    $("#dateEnd").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    var type = $("#type").val();
    if(type=="statistics") {
        $("#form2,#form3").show();
    } else {
        $("#form2,#form3").hide();
    }
});
</script>
</body>
</html>